#ifndef CU_STRING_H_
#define CU_STRING_H_

#include <inttypes.h>
#include "CuVector.h"

class CuString
{
public:
    static __device__ CuString number(int32_t num);
    static __device__ CuString number(uint32_t num);
    static __device__ CuString number(int64_t num);
    static __device__ CuString number(uint64_t num);
    
    __device__ CuString();
    __device__ CuString(const char *str);
    __device__ const char *c_str() const;

    bool operator==(const CuString& other) const;
    bool operator!=(const CuString& other) const;
    void operator+=(const CuString& other);
    
    __device__ char& operator[](int index);
    __device__ const char& operator[](int index) const;

    __device__ int size() const;
    __device__ bool isEmpty() const;

    __device__ bool endsWith(const CuString &str) const;
    __device__ bool startWith(const CuString& str) const;
    
    __device__ int indexOf(const CuString& gap,int start = 0) const;
    __device__ CuVector<CuString> split(const CuString& gap) const;
    __device__ CuString left(int num) const;
    __device__ CuString mid(int start,int len = -1) const;
    __device__ void chop(int index);


protected:
    friend __device__ CuString operator+(const CuString& str, const CuString& str2);
    friend __device__ CuString operator+(const char* str, const CuString& str2);
    friend __device__ CuString operator+(const CuString& str, const char* str2);
    friend __device__ CuString operator+(char c, const CuString& str);
    friend __device__ CuString operator+(const CuString& str, char c);

    CuVector<char> m_data;
};
__device__ CuString operator+(const CuString &str, const CuString& str2);
__device__ CuString operator+(const char *str,const CuString &str2);
__device__ CuString operator+(const CuString &str,const char *str2);
__device__ CuString operator+(char c,const CuString &str);
__device__ CuString operator+(const CuString &str, char c);

typedef CuVector<CuString> CuStringList;

__device__ int cuStrlen(const char *str);
__device__ CuString cuStrJoin(const CuStringList &list,const CuString &gap);

#endif